﻿using Shop.Models;
using Shop.Models.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace Shop.DAL
{
    public class ColorsService:BaseService<Color>
    {
        BaseService<Pictrue> pictrueService=new BaseService<Pictrue>();

        private List<string> GetPath(int colorid)
        {
            string sql= "select [Path] from [Pictrue] where colorid="+colorid;
            using (var reader = SqlHelper.ExecuteReader(sql))
            {
                List<string> list = new List<string>();
                while(reader.Read())
                {
                    list.Add(reader[0].ToString());
                }
                return list;
            }
        }

        // 查询颜色及颜色对应的图片
        public  List<ColorImage> GetColorImages(int pid)  // pid: 规格编号
        {
            string sql = "select * from color where [ProductInfoId]=" + pid;

            var reader= SqlHelper.ExecuteReader(sql);
            List<ColorImage> list= new List<ColorImage>();
            while (reader.Read())
            {
                var obj=new ColorImage();
                obj.Id = Convert.ToInt32(reader["id"]);
                obj.ColorName = reader["ColorName"].ToString();
                obj.ProductInfoId = pid;
                obj.Images = GetPath(obj.Id);

                list.Add(obj);
            }
            reader.Close();
            return list;
        }
    }
}
